yibaoPageQuotaNodesOldObj = {};//创建存放各个页面指标code的对象
function getQuotaData(nodes){
	var quotas = [];
	for(var o in nodes){
		var node = nodes[o];
		var quota = node;
		if(node.checked){
			quotas.push(quota);
			if(node.children || node.isParent){
				getCheckedNodes(node.children, quota);
			}
		}
	}
	function getCheckedNodes(nodes, quotas){
		quotas.children = [];
		for(var o in nodes){
			var node = nodes[o];
			var quota = node;
			if(node.checked){
				quotas.children.push(quota);
				if(node.children || node.isParent){
					getCheckedNodes(node.children, quota);
				}
			}
		}
	}
	return quotas;
}

//封装页面初始化开始加载指标的方法
function getQuotas(pageCode, loadData, container,monitorType){
	$.post(contextPath + "/quota/getQuotas.dhc", {pageCode: pageCode}).done(function(data){
		if(data.data.length==0){
			 drgUI.error('没有配置指标,请联系管理员');
		}
		totalQuota = arrayToTree(data.data, "id", "pid");
		var zTrees = $.extend(true, [], totalQuota);
		totalQuota = getQuotaData(totalQuota);
		loadData(totalQuota);
		loadQuotaSettings(pageCode, loadData, zTrees, container,monitorType);
	});
}

//加载指标配置页面
function loadQuotaSettings(pageCode, loadData, zTrees, container,monitorType){
	var quotaSettingBtn = $('<div class="btn-clickable" style="margin:2px;">指标配置<i class="fa fa-cog fa-lg"></i></div>');
	$("#"+tabId+" #"+container).before(quotaSettingBtn);
	if("drgs" == monitorType && ""==paramTabPage[tabId].adrgCode){
		var loadUpperBtn = $('<div class= "btn-clickable" style="margin:2px;">查看ADRG<i class="fa fa-level-up fa-lg"></i></div>');
		$(quotaSettingBtn).before(loadUpperBtn);
		loadUpperBtn.bind('click',function(){
			loadUpperStore(monitorType);
		});
	}else if("adrg" == monitorType && ""==paramTabPage[tabId].mdcCode){
		var loadUpperBtn = $('<div class= "btn-clickable" style="margin:2px;">查看MDC<i class="fa fa-level-up fa-lg"></i></div>');
		$(quotaSettingBtn).before(loadUpperBtn);
		loadUpperBtn.bind('click',function(){
			loadUpperStore(monitorType);
		});
	}
	else if(("dep" == monitorType&&""==paramTabPage[tabId].depGroupCode&&commonLayerConfig[0]=='1')||("ward" == monitorType&&""==paramTabPage[tabId].depGroupCode&&commonLayerConfig[0]=='1'&&commonLayerConfig[1]=='0')){
		var loadUpperBtn = $('<div class= "btn-clickable" style="margin:2px;">查看科室组<i class="fa fa-level-up fa-lg"></i></div>');
		$(quotaSettingBtn).before(loadUpperBtn);
		loadUpperBtn.bind('click',function(){
			loadUpperStore(monitorType);
		});
	}
	
	quotaSettingBtn.bind("click", function(){
		$.post(contextPath+"/pages/common/quota-tree.jsp").done(function(data){
			var dialog  = $(data);
			dialog.find(".modal-title").html("指标配置选项");
			var str = '';
			str += '<div class="zTreeDemoBackground">';
			str += '<ul id="treeDemo" class="ztree"></ul>';
			str += '</div>';
			dialog.find(".echartscq").html(str);
			
			var setting = {
					view: {
						selectedMulti: false
					},
					check: {
						enable: true
					}
				};
			$.fn.zTree.init(dialog.find("#treeDemo"), setting, zTrees);
			
			var zTreeSimp = "";//需要保存的指标数组
			//确定按钮绑定事件
			dialog.find('#save').on('click', function(){
				dialog.find('#save').attr("disabled", true);
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTrees = zTree.getNodes();
				
				//获取需要保存的指标数组
				zTreeSimp = zTree.transformToArray(zTrees);
				
				//获取选中的指标
				var nodes =  $.extend(true, [], zTrees);
				totalQuota = getQuotaData(nodes);
				
				dialog.trigger('complete');
				
				
			}).end().modal({
				keyboard : false
			}).on({
				'hidden.bs.modal' : function() {
					dialog.remove();
				},
				'complete' : function() {
					//隐藏树弹框
					dialog.modal('hide');
					//正在加载
					
					//循环保存指标
					for(var o in zTreeSimp){
						var node = zTreeSimp[o];
						node.pageCode = pageCode;
						$.post(contextPath + "/quota/saveQuotas.dhc", {param: JSON.stringify(node)}).done(function(data){
						})
					}
					
					//加载页面指标
					loadData(totalQuota);
	            }
			});
			
			//重置按钮绑定事件
			dialog.find('#clear').on('click', function(){
				drgUI.confirm({
        			content : '即将恢复默认页面指标配置，是否恢复？',
        			callSure : function() {
        				$.post(contextPath + "/quota/clearQuotaSettings.dhc", {pageCode: pageCode}).done(function(data){
        					$.post(contextPath + "/quota/getQuotas.dhc", {pageCode: pageCode}).done(function(data_1){
        						if(data_1.data.length==0){
        							 drgUI.error('没有配置指标,请联系管理员');
        							return;
        						}
        						totalQuota = arrayToTree(data_1.data, "id", "pid");
        						var zTrees = $.extend(true, [], totalQuota);
        						$.fn.zTree.init(dialog.find("#treeDemo"), setting, zTrees);
        					});
        				});
        			}
        		});
			});
		})
	});
}

/**
 * 获取页面全院数据以及加载页面
 * @param {} monitorType 搜索类型
 * @param {} quotaCode 指标code
 * @param {} totalQuota 可配置指标组
 * @param {} divId 对应的jsp页面中的div 的id
 * @param {} commonul对应的jsp页面中的ul 的id
 */
function loadHospQuota(monitorType,totalQuota,divId,commonul, pageCode){
	var pageQuotaNodesTemporary = new Array(); //创建一个临时数组
	var str = '';
	var ul = '';
	for(var o in totalQuota){
		var quotaTypes = totalQuota[o].children;				 
		if(totalQuota.length > 0){				 	
			if(o == 0){
				ul+='<li role="presentation" class="active">';
			}else{
				ul+='<li role="presentation">';
			}
			ul+='<a href="#'+totalQuota[o].code+'QuaId-hosp'+tabId+'" role="tab" data-toggle="tab">'+totalQuota[o].name+'</a>';
			ul+='</li>';
			$("#"+tabId+" #"+commonul).html(ul);
			//开始拼接div
			if(o == 0){
				str+='<div role="tabpanel" class="tab-pane active" id="'+totalQuota[o].code+'QuaId-hosp'+tabId+'">';
			}else{
				str+='<div role="tabpanel" class="tab-pane" id="'+totalQuota[o].code+'QuaId-hosp'+tabId+'">';
			}
			str+='<div class="paddingd10">';
			str+='<div class="row" >';
		}
		for(var o in quotaTypes){
			var quotas = quotaTypes[o];
			var width = 100/(quotaTypes.length);
			if(quotaTypes.length <= 3){
				str+=' <div class="col-xs-4"> ';
			}else{
				str+=' <div style="width:'+width+'%; float:left;"> ';
			}
			str+='     <div class="infocq"> ';
			str += '         <div class="tii margind10'
				if(quotas.name==='产能'){
					str += ' blue-bg"><span><i class="fa fa-users fa-lg"></i>';
				} else if(quotas.name==='效率'){
					str += ' green-bg"><span><i class="fa fa-stethoscope fa-lg"></i>';
				} else if(quotas.name==='安全'){
					str += ' red-bg"><span><i class="fa fa-heartbeat fa-lg"></i>';
				} else {
					str += '"><span>';
				}
				str += quotas.name + '</span></div> ';
			str+='         <div class="ci"> ';
			for(var o1 in quotas.children){
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var quotaType = quota.type;
				var isLink = quota.islink;//是否有超链接
				if(quotaCode=='FeeEffContri')
				{//费用消耗指数贡献度  汇总时 有当前指标直接跳过  不加载
					continue;
				}
				
				
				/**
				 * 此处循环加载页面指标，包括渲染页面及加载数据
				 * 加载过的指标 不再加载，直接取到该指标的html代码 追加赋值给str
				 * 没加载过的指标 重新加载
				 * 重新生成页面指标数组---yibaoPageQuotaNodesOldObj[pageCode]
				 */
				//原来页面显示的指标数组
				var yibaoPageQuotaNodesOldTotal = yibaoPageQuotaNodesOldObj[pageCode];
				if(yibaoPageQuotaNodesOldTotal != null && yibaoPageQuotaNodesOldTotal.length > 0 && !($.inArray(quotaCode, yibaoPageQuotaNodesOldTotal) == -1)){//指标code在原来的页面已经存在
					var quotaOldDiv = $('#' + tabId + ' div[quotaCode="'+quotaCode+'"]').prop("outerHTML");//获取原有的指标页面div
					str += quotaOldDiv;
				}else{
				
					str+='             <div class="row contotalcq2" quotaCode="'+quotaCode+'"> ';
					str+='                 <div class="col-xs-5">'+quotaName+'</div> ';
					if("ratio"==quotaType){
						str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode,quotaName, monitorType,isLink, function(value, valuecc, code,name,isLink){
							$("#" + tabId + " #" + divId + " #"+code+"-value").html(comparePercent(value, valuecc));
						})+'</div> ';
					}else{
						str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode,quotaName, monitorType,isLink, function(value, valuecc, code, name,isLink){
							if(isLink==1){
								var str = compareValue(value, valuecc);//数值比较的字符串
								var reg = /<span class= \"number\".*?>.*?<\/span>/; //正则表达式 匹配 html 中 class = "number" 的span标签
								var num = str.match(reg);//数字串
								if(num==null)
								{
									num = "";
									$("#" + tabId + " #" + divId + " #"+code+"-value").html(str);
								}
								else
								{
									num = num[0];
									var symbol = str.replace(reg, "");//符号串
									if(value>0){
										$("#" + tabId + " #" + divId + " #"+code+"-value").html("<a href=\"javascript:loadCaseDtl('"+name+"','','"+monitorType+"', '"+code+"')\">"+num+"</a>"+symbol);
									} else {
										$("#" + tabId + " #" + divId + " #"+code+"-value").html(compareValue(value, valuecc));
									}
								}
							}
							else
							{
								$("#" + tabId + " #" + divId + " #"+code+"-value").html(compareValue(value, valuecc));
							}
						})+'</div> ';
					}
					str+='             </div> ';
				
				}
				
				/**
				 * 将页面加载的指标code放到临时数组pageQuotaNodesTemporary
				 */
					pageQuotaNodesTemporary.push(quotaCode);
				
			}
			str+='         </div> ';
			str+='     </div> ';
			str+=' </div> ';
		}
		if(totalQuota.length > 0){
			str+='</div>';
			str+='</div>';
			str+='</div>';
		}
	}
	//将页面加载的指标code数组添加到对象
	yibaoPageQuotaNodesOldObj[pageCode] = pageQuotaNodesTemporary;
	$("#"+tabId+" #"+divId).html(str);
}

function getQuotaValue(quotaCode,quotaName, monitorType,isLink, callback){
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc='1';//是否获取比较值
	param.monitorType=monitorType;//比较对象： Hosp dep depGroup  mdc adrg drgs ward（病区） resident（住院医师） protomedicus（主任医师）physician（主治医师）
	param.quotaCode=quotaCode;//指标代码
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(data) {
		if(data.success){
			if(data.data.length>0){
				data = data.data[0];
				callback(data.QuotaValue, data.QuotaValuecc, quotaCode, quotaName,isLink);
			}else{
				callback("", "", quotaCode, quotaName,isLink);
			}
		}else{
			callback("", "", quotaCode, quotaName,isLink);
		}
	});
	return "";
}
/**
 * 拼接页面下半部分页面布局
 * @param {} totalQuota totalQuota 可配置指标组
 * @param {} monitorName 右边表格中第一例表头的名称
 * @param {} divId 对应的jsp页面中的div 的id
 * @param {} commonul对应的jsp页面中的ul 的id
 */
function loadDRGsQuota(totalQuota,monitorType,monitorName,divId,commonul){
			if(!monitorName) monitorName = ""
			if(paramTabPage[tabId].compareType=="year"){
				compareName = "同期";
			}else if(paramTabPage[tabId].compareType=="month"){
				compareName = "上期";
			}else if(paramTabPage[tabId].compareType=="manage"){
				compareName = "绩效";
			}else if(paramTabPage[tabId].compareType=="std"){
				compareName = "标杆";
			}
			var str = '';
			var ul='';			
		for(var o in totalQuota){
			var QuotaCode = totalQuota[o].children;
			var flagCode = totalQuota[o].code;
			//拼接ul
			if(totalQuota.length>0){
			if(o == 0){
				ul+='<li role="presentation" class="active">';
			}else{
				ul+='<li role="presentation">';
			}
			ul+='<a class="top-tab" href="#'+totalQuota[o].code+'QuaId'+tabId+'" role="tab" data-toggle="tab">'+totalQuota[o].name+'</a>';
			ul+='</li>';
			$("#"+tabId+" #"+commonul).html(ul);
			}
		//开始拼接div
			if(o == 0){
				str+='<div role="tabpanel" class="tab-pane active" id="'+totalQuota[o].code+'QuaId'+tabId+'">';
			}else{
				str+='<div role="tabpanel" class="tab-pane" id="'+totalQuota[o].code+'QuaId'+tabId+'">';
			}
			
			for(var o in QuotaCode){
				var quotas = QuotaCode[o];
				str+=' <div class="paddingd10"> ';
				str += '   <div class="tabconti';
				if(quotas.name==='产能'){
					str += ' blue-bg"><i class="fa fa-users fa-lg"></i>';
				} else if(quotas.name==='效率'){
					str += ' green-bg"><i class="fa fa-stethoscope fa-lg"></i>';
				} else if(quotas.name==='安全'){
					str += ' red-bg"><i class="fa fa-heartbeat fa-lg"></i>';
				} else {
					str += '">';
				}
				str += quotas.name + '</div> ';
				str+='   <ul class="nav nav-tabs tabconulcq" role="tablist"> ';
				for(var o1 in quotas.children){
					var quota = quotas.children[o1];
					var quotaCode = quota.code;
					var quotaName = quota.name;
					if(o1 == 0){
						str+='       <li role="presentation" class="active"> ';
					}else{
						str+='       <li role="presentation"> ';
					}
					str+='           <a href="#'+quotaCode+'-tc'+tabId+'" role="tab" data-toggle="tab">'+quotaName+'</a> ';
					str+='       </li> ';
				}
				str+='   </ul> ';
				str+='   <div class="clearfix"></div> ';
				str+='   <div class="tab-content"> ';
				for(var o1 in quotas.children){
					var quota = quotas.children[o1];
					var quotaCode = quota.code;
					var quotaName = quota.name;
					var releate = quota.releate;
					if(o1 == 0){
						str+='       <div role="tabpanel" class="tab-pane active" compareName="'+compareName+'" monitorName="'+monitorName+'" quotaName="'+quotaName+'" quotaCode="'+quotaCode+'" id="'+quotaCode+'-tc'+tabId+'"> ';
					}else{
						str+='       <div role="tabpanel" class="tab-pane" compareName="'+compareName+'" monitorName="'+monitorName+'" quotaName="'+quotaName+'" quotaCode="'+quotaCode+'" id="'+quotaCode+'-tc'+tabId+'"> ';
					}
					str+='           <div class="row padding100"> ';
					str+='               <div class="col-xs-5"> ';
					str+=' 					<ul class="nav nav-tabs tabconulcq" role="tablist" quota_code="'+quotaCode+'">  ';
					str+=' 						<li role="presentation" class="active">  ';
					str+=' 						<a href="#'+quotaCode+'bar-tc'+tabId+'" role="tab" data-toggle="tab">柱状图</a>  ';
					str+=' 						</li>  ';
					str+=' 						<li role="presentation">  ';
					str+=' 						<a href="#'+quotaCode+'line-tc'+tabId+'" role="tab" data-toggle="tab">趋势图</a>  ';
					str+=' 						</li>  ';
					if(quota.releate)
					{
						str+='       <li role="presentation" code = "'+flagCode+'" class = "pull-right releated"> <i class="icon-magnet" title = "关联指标"></i>';
						str+='       </li> ';
					}
					str+='					</ul>'
					str+=' 			<div class="tab-content"> ';
					str+=' 				<div role="tabpanel" class="tab-pane active" id="'+quotaCode+'bar-tc'+tabId+'"> ';
					str+=' 					<div class="echartscq" style="width:475px;"><img src="images/pageloading.gif" /></div> ';
					str+=' 				</div> ';
					str+=' 				<div role="tabpanel" class="tab-pane" id="'+quotaCode+'line-tc'+tabId+'"> ';
					str+=' 					<div class="echartscq" style="width:475px;"></div> ';
					str+=' 				</div> ';
					str+=' 			</div> ';
					str+='               </div> ';
					str+='               <div class="col-xs-7 dataChangeSel"> ';
					str+='                   <table id="'+quotaCode+'-table'+tabId+'" class="table table-striped" cellspacing="0" width="100%" role="grid" aria-describedby="example_info"> ';
					str+='                       <caption class="contaotalsccq">'+monitorName+quotas.name+'('+quotaName+')</caption> ';
					str+='                       <thead> ';
					str+='                           <tr role="row"> ';
					if(releate){
						str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1"></th> ';
					}
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending">'+monitorName+'</th> ';
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">本期值</th> ';
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">'+compareName+'值</th> ';
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">增长率</th> ';
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">操作</th> ';
					str+='                           </tr> ';
					str+='                       </thead> ';
					str+='                       <tbody></tbody> ';
					str+='                   </table> ';
					str+='               </div> ';
					str+='           </div> ';
					str+='       </div> ';
				}
				str+='   </div> ';
				str+=' </div> ';
			}
			str+='</div>';
			
		}
		$("#"+tabId+" #"+divId).html(str);
		//给 相关指标 添加单击事件
		$("#"+tabId+" .releated").click(
		
				function(){
					//获取要查询的关联指标的指标代码
					var quota_rel = $(this).parents("ul").attr("quota_code");
					var quotaName = $(this).parents(".tab-pane").attr("quotaName");
					var flagCode = $(this).attr("code");
					//请求当前指标的关联指标
					$.ajax({
					    url: contextPath+"/DrgsIndexCal/releateQuotas.dhc?quotaCode="+quota_rel+"_RELEATE",
					    type: "POST",
					    dataType: 'JSON',
					    async: false,
					    success: function(result){
					    	var relQuota = result.data;
					    	loadDRGsQuotaRelData(quota_rel,quotaName,monitorName,monitorType,relQuota,flagCode)
					    },
					    error: function(result){
					    	
					    }
					});
				}
		);	
	}
		
		/**
		 * 为页面下半部分指标加载数据以及图标
		 * @param {} totalQuota totalQuota totalQuota 可配置指标组
		 * @param {} monitorType 获取数据类型
		 * @param {} across 是否交叉
		 */
function loadDRGsQuotaData(totalQuota,monitorType,across,pageCode){
		for(var o in totalQuota){
			var quotaTypes = totalQuota[o].children;
			for(var o in quotaTypes){
				var quotas = quotaTypes[o];
				for(var o1 in quotas.children){
					var quota = quotas.children[o1];
					var quotaCode = quota.code;
					var quotaName = quota.name;
					var quotaType = quota.type;
					var releate = quota.releate;
					var isLink = quota.islink;
					
					/**
					 * 此处循环加载页面指标数据
					 * 加载过的指标 不再加载，直接取到该指标历史页面加载数据
					 * 没加载过的指标 重新加载
					 * 
					 */
					//loadDRGsQuotaDatasub(quotaCode, quotaType, releate, quotaName,monitorType,across,isLink,pageCode);
					
					if(yibaoPageQuotaNodesOldObj != null && yibaoPageQuotaNodesOldObj.hasOwnProperty(pageCode+"-"+quotaCode)){//指标code在原来的页面已经存在
						
						
						var quotaData = yibaoPageQuotaNodesOldObj[pageCode+"-"+quotaCode];//获取原有页面加载的指标数据
						var quotaColumns = yibaoPageQuotaNodesOldObj[pageCode+"-"+quotaCode+"-columns"];//获取原有页面加载datatable属性
						var unSortColumnI = 4;
						if(releate){
							unSortColumnI = 5;
						}
						var paramsDataTables={order:[],columnDefs:[{"orderable": false,"targets":[unSortColumnI] }],monitorType:monitorType};
						if(releate){
							paramsDataTables.columnDefs.push({ "orderable": false,"targets": [ 0 ] });
						}
						$("#"+quotaCode+"-table"+tabId).drgsDataTableyb(quotaColumns, quotaData, paramsDataTables);
					}else{
						loadDRGsQuotaDatasub(quotaCode, quotaType, releate, quotaName,monitorType,across,isLink,pageCode);
					}
				}
			}
		}
	}
/**
 * 加载数据回调方法
 * @param {} quotaCode 指标code
 * @param {} quotaName指标名称
 * @param {} monitorType获取数据类型
 * @param {} functionOne 第一例链接方法
 * @param {} operfunctionOne 操作中的链接方法
 */
function loadDRGsQuotaDatasub(quotaCode, quotaType, releate, quotaName,monitorType,across,isLink,pageCode){
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc='1';
	param.monitorType=monitorType;
	param.quotaCode=quotaCode;
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(data){
		data = data.data;
		//将页面加载的指标code数组添加到对象
		yibaoPageQuotaNodesOldObj[pageCode+"-"+quotaCode] = data;		 
		var hasCaseDtl = isLink==1?true:false;
		var columns = [
		               { "data": "ccode",
		               	 "createdCell": function (nTd, sData, oData, iRow, iCol) {
							  $(nTd).attr('limit', 30);
							  $(nTd).limit();
						   },
	               		"render":function(obj, type, full){
	               			if(full.ccode==null||full.ccode=="null"){
	               				return "未入组";
               				}else if(monitorType=="mdc"||monitorType=="adrg"){//病组线   mdc或adrg
               					if(full.ccode=="notcode"){
               						return "未入组";
               					}
	               				return "<a title ='' href=\"javascript:toNextLayerYiBao("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" +full.ccode+"-"+full.ddesc + "</a><input value="+full.ccode+" style='display:none;'>";
               				}else if(monitorType=="drgs"){
               					if(full.ccode=="notcode"){
               						return "未入组";
               					}
               					return full.ccode+"-"+full.ddesc+"<input value="+full.ccode+" style='display:none;'>";
               				}else{
	               				if (toNextLayerBool(monitorType)) {
	               					return "<a title ='' href=\"javascript:toNextLayerYiBao("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" + full.ddesc + "</a><input value="+full.ccode+" style='display:none;'>";
	               				} else {
	               					return full.ddesc+"<input value="+full.ccode+" style='display:none;'>";
               					}
               				}
	               		}
	               	},{ "data": "QuotaValue", "type": "numeric-comma",
	            	     "render":function(obj, type, full){
	            	    	 full.QuotaValue=full.QuotaValue!=null?full.QuotaValue:'';//强制转换
	            	    	 full.QuotaValuecc=full.QuotaValuecc!=null?full.QuotaValuecc:'';
	            	    	 if(hasCaseDtl && full.QuotaValue!=0 ){
	            	    		 return "<a href=\"javascript:loadCaseDtl('"+full.ddesc+"|"+quotaName+"','"+full.ccode+"','"+monitorType+"', '"+quotaCode+"' )\">"+formatNumber(full.QuotaValue)+"</a>"
            	    		 }
	            	    	 return formatNumber(full.QuotaValue);   
	            	   }
	               	},{ "data": "QuotaValuecc", "type": "numeric-comma",
		            	"render":function(obj, type, full){
		            			   return formatNumber(full.QuotaValuecc);   
		            	   }
	               	},	{ "data": "increasing","type": "number-fate",
	               		  "render":function(obj, type, full){
	               			if("ratio"==quotaType){
	               				return gridcompareValuePercent(full.QuotaValue, full.QuotaValuecc);
	               			}
	               			return gridcompareValue(full.QuotaValue, full.QuotaValuecc);
	               		}
	               	},	{ "data": "OPERATION",
	               		  "render":function(obj, type, full){
	               			if(across){//交叉的情况	科室线下各病种层次	病区线下各科室层次
	               				var operation = "";
	               				if(monitorType == "drgs"&&(param.previous.match("depGroup|dep|ward"))){
	               					operation = "<a href=\"javascript:yiBaoDrgToDepLine('"+ full.ccode+ "', '"+ full.ddesc+ "')\" class='jumplink'><i class='fa fa-hospital-o'></i></a>&nbsp;&nbsp;";
	               				}
	               				return operation
	               				+ "<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"								
               					+ "<a title='趋势' class='trend-link  trendNotSel'><i class='fa fa-line-chart'></i></a>";
               				}else{
	               				if(monitorType=="mdc"||monitorType=="adrg"||monitorType=="drgs"){
	               					if(full.ccode==null){
		               				return "<span><i class='fa fa-hospital-o'></i></span>&nbsp;&nbsp;"								
		               				+ "<a title='趋势' class='trend-link trendNotSel'><i class='fa fa-line-chart'></i></a>";

	               					}
	               					return "<a title='科室' href=\"javascript:ybbDisToDep('"+ full.ccode+ "', '"+ full.ddesc+ "', '"+ monitorType+ "')\" class='jumplink'><i class='fa fa-hospital-o'></i></a>&nbsp;&nbsp;"								
	               						+ "<a title='入组病例' href=\"javascript:loadDetail('"+ full.ccode+ "', '"+ full.ddesc+ "', '"+ monitorType+ "')\" class='jumplink'><i class='fa fa-users'></i></a>&nbsp;&nbsp;"								
	               						+ "<a title='趋势' class='trend-link trendNotSel'><i class='fa fa-line-chart'></i></a>";
	               				}else if(monitorType=="depGroup"||monitorType=="dep"||monitorType=="ward"||monitorType=="clinic"){
	               					var operation = "";
	               					if (typeof (param.disBack) == "undefined") {
	               						operation = "<a title='病组' class='jumplink' href=\"javascript:loadDRGs('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-list-alt'></i></a>&nbsp;&nbsp;"
	               					}
	               					return operation 
	               					+ "<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"								
	               					+ "<a title='趋势' class='trend-link trendNotSel'><i class='fa fa-line-chart'></i></a>" ;
	               				}
               				}
               			}
	               	}];
	var unSortColumnI = 4;
	if(releate){
		columns.splice(0, 0, {
			"data":null,"defaultContent": "","width":"25","className": 'details-control'
		});
		unSortColumnI = 5;
	}
	
	//将页面加载的指标code数组添加到对象
	yibaoPageQuotaNodesOldObj[pageCode+"-"+quotaCode+"-columns"] = columns;
	//调用datatableyb画右侧表格
	var paramsDataTables={order:[],columnDefs:[{"orderable": false,"targets":[unSortColumnI] }],monitorType:monitorType};
	if(releate){
		paramsDataTables.columnDefs.push({ "orderable": false,"targets": [ 0 ] });
	}
	$("#"+quotaCode+"-table"+tabId).drgsDataTableyb(columns, data, paramsDataTables);
 });
}

/**
 * 判断是否有下一层
 * @param monitorType 取值 depGroup dep ward clinic
 * @returns {Boolean}
 */
function toNextLayerBool(monitorType){
	var bool = false;
	switch(monitorType){
	case "depGroup":
		if(commonLayerConfig.length>=4&&(commonLayerConfig[1]=='1'||commonLayerConfig[2]=='1')){
			bool = true;
		}
		break;
	case "dep":
		if(commonLayerConfig.length>=4&&(commonLayerConfig[2]=='1'||commonLayerConfig[3]=='1')){bool = true;}
		break;
	case "ward":
		if(commonLayerConfig.length>=4&&commonLayerConfig[3]=='1'){bool = true;}
		break;
	case "mdc":
		bool = true;
		break;
	case "adrg":
		bool = true;
		break;
	}
	return bool;	
}

/**
 * 跳往下一个层级
 * across 标识是否交叉
 * monitorType 页面所处的层次 depGroup dep ward clinic
 * code某一层级的代码
 * name某一层级的名称
 */
function toNextLayerYiBao(across,monitorType,code,name){
	var param = jQuery.extend(true,{},paramTabPage[tabId]);//参数
	param.previous = monitorType;//指示当前的层次
	var destUrl = "";
	var pageId = "";
	var disBack = "";
	if(typeof(param.disBack)!="undefined"){
		disBack = "1";
	}
	switch(monitorType){
	case "depGroup":
		param.depGroupCode = code;
		param.depGroupName = name;
		if(commonLayerConfig.length>=4){
			if(commonLayerConfig[1]=='1'){
				if(across){//病种线下的科室组跳往科室
					destUrl = "/pages/yibao/keshi/ybbDisLineDep.jsp";
					pageId = code+"yiBao_DepGroup_To_DisLineDep";
				}else{//科室线科室组跳往科室
					destUrl = "/pages/yibao/keshi/ybbDep.jsp";
					pageId = code+disBack+"yiBao_DepGroup_To_Dep";
				}
			}else if(commonLayerConfig[2]=='1'){
				if(across){//病种线下的科室组跳往病区
					destUrl = "/pages/yibao/keshi/ybbDisLineWard.jsp";
					pageId = code+"yiBao_DepGroup_To_DisLineWard";
				}else{//科室线科室组跳往病区
					destUrl = "/pages/yibao/keshi/ybbWard.jsp";
					pageId = code+disBack+"yiBao_DepGroup_To_Ward";
				}
			}
		}
		break;
	case "dep":
		param.depCode = code;
		param.depName = name;
		if(commonLayerConfig.length>=4){
			if(commonLayerConfig[2]=='1'){
				if(across){//病种线下的科室跳往病区
					destUrl = "/pages/yibao/keshi/ybbDisLineWard.jsp";
					pageId = code+"yiBao_Dep_To_DisLineWard";
				}else{//科室线科室跳往病区
					destUrl = "/pages/yibao/keshi/ybbWard.jsp";
					pageId = code+disBack+"yiBao_Dep_To_Ward";
				}
			}else if(commonLayerConfig[3]=='1'){
				if(across){//病种线下的科室跳往主诊组
					destUrl = "/pages/yibao/keshi/ybbDisLineClinic.jsp";
					pageId = code+"yiBao_Dep_To_DisLineClinic";
				}else{//科室线科室跳往主诊组
					destUrl = "/pages/yibao/keshi/ybbClinic.jsp";
					pageId = code+disBack+"yiBao_Dep_To_Clinic";
				}
			}
		}
		break;
	case "ward":
		param.wardCode = code;
		param.wardName = name;
		if(commonLayerConfig.length>=4){
			if(commonLayerConfig[3]=='1'){
				if(across){//病种线下的病区跳往主诊组
					destUrl = "/pages/yibao/keshi/ybbDisLineClinic.jsp";
					pageId = code+"yiBao_Ward_To_DisLineClinic";
				}else{//科室线病区跳往主诊组
					destUrl = "/pages/yibao/keshi/ybbClinic.jsp";
					pageId = code+disBack+"yiBao_Ward_To_Clinic";
				}
			}
		}
		break;
	case "mdc":
		param.mdcCode = code;
		param.mdcName = name;
		if(across){//科室线下的MDC跳往ADRG
			destUrl = "/pages/yibao/bingzhong/ybbDepLineAdrg.jsp";
			pageId = code+"yiBao_Mdc_To_DepLineAdrg";
		}else{//病种线MDC跳往ADRG
			destUrl = "/pages/yibao/bingzhong/ybbAdrg.jsp";
			pageId = code+"yiBao_Mdc_To_Adrg";
		}
		break;
	case "adrg":
		param.adrgCode = code;
		param.adrgName = name;
		if(across){//科室线下的ADRG跳往DRG
			destUrl = "/pages/yibao/bingzhong/ybbDepLineDrg.jsp";
			pageId = code+"yiBao_Adrg_To_DepLineDrg";
		}else{//病种线ADRG跳往DRG
			destUrl = "/pages/yibao/bingzhong/ybbDrg.jsp";
			pageId = code+"yiBao_Adrg_To_Drg";
		}
		break;
	}
	if(destUrl!=""){
		openTab(destUrl, name+"指标监测",pageId, pageId,param);
	}	
}

/**
* 医政角色病种线 跳往科室线
* @param code 病种层代码
* @param desc 病种层描述
* @param type 监测类型
*/
function ybbDisToDep(code, desc, type){
	var param = jQuery.extend(true, {}, paramTabPage[tabId]);
	param.code = code;
	param.desc = desc;
	param.type = type;
	param.monitorType = type;
	param.previous=type;
	var destUrl = ""; 
	var depLayerName = "";
	var depLayer = "";
	if(commonLayerConfig[1]=="1"){
		destUrl = "/pages/yibao/keshi/ybbDisLineDep.jsp";
		depLayerName = "科室";
		depLayer = "dep";
	}else if(commonLayerConfig[2]=="1"){
		destUrl = "/pages/yibao/keshi/ybbDisLineWard.jsp";
		depLayerName = "病区";
		depLayer = "ward";
	}
	var disLineToDepTitle ="";
	var disLineToDepPageId ="";
	switch(param.monitorType){
	case "mdc":
		param.mdcCode = param.code;
		param.mdcDesc = param.desc;
		param.title = "MDC指标";
		disLineToDepTitle = param.mdcCode+"|"+depLayerName;
		disLineToDepPageId = "yibao"+"_"+"mdc"+"_"+param.mdcCode+"_todepline"+"_"+depLayer;
		break;
	case "adrg":
		param.adrgCode = param.code;
		param.adrgDesc = param.desc;
		param.title = "ADRG指标";
		disLineToDepTitle = param.adrgCode+"|"+depLayerName;
		disLineToDepPageId = "yibao"+"_"+"adrg"+"_"+param.adrgCode+"_todepline"+"_"+depLayer;
		break;
	case "drgs":
		param.drgCode = param.code;
		param.drgDesc = param.desc;
		param.title = "DRG指标";
		disLineToDepTitle = param.drgCode+"|"+depLayerName;
		disLineToDepPageId = "yibao"+"_"+"drg"+"_"+param.drgCode+"_todepline"+"_"+depLayer;
		break;
	}
	openTab(destUrl,disLineToDepTitle,disLineToDepPageId,disLineToDepPageId,param);

}

/**
 * 
 * @ Discription:DRG层级下钻科室线层级
 * @Autor ：mazhaoyan
 * @param code
 * @param desc
 * @param type
 * void
 * ywcCommon.js
 * 2018年2月9日上午11:40:46
 */
function yiBaoDrgToDepLine(code, desc){
	var destUrl = ""; 
	var pageId = "";
	var param = jQuery.extend(true, {}, paramTabPage[tabId]);
	param.drgCode = code;
	param.disBack = "1";
	var previous = param.previous;
	switch(previous){
	case "depGroup":
		if(commonLayerConfig[1]=="1"){
			destUrl = "/pages/yibao/keshi/ybbDep.jsp";
			pageId = code+"yibao_drg_Dg_To_Dep";
		}else if(commonLayerConfig[2]=="1"){
			destUrl = "/pages/yibao/keshi/ybbWard.jsp";
			pageId = code+"yibao_drg_Dg_To_ward";
		}
		break;
	case "dep":
		if(commonLayerConfig[2]=="1"){
			destUrl = "/pages/yibao/keshi/ybbWard.jsp";
			pageId = code+"yibao_drg_Dep_To_Ward";
		}else if(commonLayerConfig[3]=="1")	{
			destUrl = "/pages/yizheng/ywcClinic.jsp";
			pageId = code+"yibao_drg_Dep_To_clinic";
		}
		break;
	case "ward":
		if(commonLayerConfig[3]=="1"){
			destUrl = "/pages/yibao/keshi/ybbClinic.jsp";
			pageId = code+"yibao_drg_Ward_To_Clinic";
		}
		break;
	}
	openTab(destUrl, desc+"|"+"指标监测",pageId, pageId,param);
}
/**
 * 获取病例信息
 * @param {} code 获取病例的code
 * @param {} desc
 * @param {} type
 */
function loadDetail(code,desc,type){
	var param = jQuery.extend(true,{},paramTabPage[tabId]);
	param.caseLinkCode = "InCaseCnt";
	if (type =="drgs") {
		 param.drgCode = code;
		 if(desc == null || desc=="null"|| desc=="未维护编码"){
			desc="未入组";
		}
	}else if (type == "adrg") {
		param.adrgCode = code;
		if(desc == null || desc=="null"|| desc=="未维护编码"){
			desc="未入组";
		}
	}else if (type == "mdc") {
		param.mdcCode = code;
		if(desc == null || desc=="null"|| desc=="未维护编码"){
			desc="未入组";
		}
	}else if (type == "depGroup") {
		param.depGroupCode = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "dep") {
		param.depCode = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "ward") {
		param.wardCode = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if(type =="clinic"){
		param.groupName = code;
		if(desc==null || desc=="null"){
			desc="其他";
		}
	}else if (type == "protomedicus") {
		//主任医师
		param.protomedicus = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "physician") {
		//主治医师
		param.physician = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "resident") {
		//住院医师
		param.resident = code;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}
//	openTab('/pages/drgscommon/case.jsp', desc+'病例', type+code+'Case' , type+code+'Case', param);
	openTab('/pages/drgscommon/case.jsp', desc +"|"+ '病例明细', type + code + 'Case', type + code + 'Case', param);
}


/**
 * 
 * @param quotaCode 指标代码
 * @param quotaName 指标名称
 * @param monitorName 监测名称
 * @param monitorType 监测类型
 * @param relQuota 关联指标
 */
function loadDRGsQuotaRelData(quotaCode,quotaName,monitorName,monitorType,relQuota,flagCode){
	$.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
		var dialog  = $(data);
		dialog.find(".modal-title").html(quotaName+"关联指标");
		dialog.modal({
			keyboard: false
		}).on({
			'hidden.bs.modal' : function(){
				$(this).remove();
			},
			'shown.bs.modal' : function(){
				var param=drgUI.setAjaxData(tabId);
				param.isGetCc='1';
				param.monitorType=monitorType;
				param.quotaCode=quotaCode+"_RELEATE"; //指标代码
				$.post(contextPath+"/DrgsIndexCal/indexCal.dhc",param).done(function(data){
					 data = data.data;
					 if((data[data.length-1].ccode==null||data[data.length-1].ccode=="null")&&flagCode=="drgs")
					 {
						 data.splice(data.length-1, 1);
					 }
					 var columns = [];
					 var column = {"data": "ddescRelated",
							 "render":function(obj, type, full){
								 if(monitorType == "mdc" || monitorType == "adrg" || monitorType == "drgs"){
									 if(full.ccode==null||full.ccode=='null'|| full.ccode=="未维护编码")
									 {return "未入组";}
									 return full.ccode+"-"+full.ddesc;
								 }else{
									 return full.ddesc;
								 }
								 return full.ddesc;
							 }};
					 columns.push(column);
					 var ajaxCount = relQuota.length;
					 for(var i=0;i<relQuota.length;i++)
					 {
						 var tmpCode = relQuota[i][0];
						 col(tmpCode);
					 }
					 
					 function col(quotaCode){
						 var column = { 
								 		"data": quotaCode,"type":"numeric-comma",
								 	"render":function(obj, type, full){
							 			return formatNumber(full[quotaCode]);
							 		}
					 			};
						 columns.push(column);
						 ajaxCount--;
					 }
					 
					 var timerId = window.setInterval(function(){
						 if(ajaxCount == 0){
							 window.clearInterval(timerId);
							 var str = "";
								str+='<table id="'+quotaCode+'-releate-table'+tabId+'" class="table table-striped" cellspacing="0" width="100%" role="grid" aria-describedby="example_info"> ';
								//str+='	<caption class="contaotalsccq"></caption> ';
								str+='	<thead> ';
								str+='		<tr role="row"> ';
								str+='			<th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending">'+monitorName+'</th> ';
								for(var i=0;i<relQuota.length;i++)
								{
									str+='		<th tabindex="0" aria-controls="example" rowspan="1" colspan="1">'+relQuota[i][2]+'</th> ';
								}
								str+='		</tr> ';
								str+='	</thead> ';
								str+='	<tbody></tbody> ';
								str+='</table> ';
							dialog.find(".echartscq").empty();
							dialog.find(".echartscq").css("width",860)
							$(str).appendTo(dialog.find(".echartscq"))
							var paramsDataTables={order:[]};
							$("#"+quotaCode+"-releate-table"+tabId).drgsDataTableyb(columns, data, paramsDataTables);
						 }
					 },1000)	 
					})
			}
		});
 });
}

/**
 * 提示未入组数据
 */

function alertData(){
	 drgUI.warning('未入组数据!');
	return;
}
/**
 * 加载病例详细
 * @param title
 * @param ccode
 * @param monitorType
 * @param quotaCode
 */
function loadCaseDtl(title, ccode, monitorType, quotaCode){
	var param = jQuery.extend(true, {}, paramTabPage[tabId]);
	param.caseLinkCode = quotaCode;
	if(ccode){
		if(monitorType == "depGroup"){
			param.depGroupCode=ccode;
		}else if(monitorType == "dep"){
			param.depCode=ccode;
		}else if(monitorType == "ward"){
			param.wardCode=ccode;
		}else if(monitorType == "clinic"){
			param.groupName=ccode;
		}else if(monitorType == "protomedicus"){
			param.protomedicus=ccode;
		}else if(monitorType == "physician"){
			param.physician=ccode;
		}else if(monitorType == "resident"){
			param.resident=ccode;
		}else if(monitorType == "mdc"){
			param.mdcCode=ccode;
		}else if(monitorType == "adrg"){
			param.adrgCode=ccode;
		}else if(monitorType == "drgs"){
			param.drgCode=ccode;
		}
	}
	openTab('/pages/drgscommon/case.jsp', title+"|"+"病例明细", "caseDtl"+monitorType+ccode+quotaCode, "caseDtl"+monitorType+ccode+quotaCode, param);
}

function loadDRGs(code, desc, type) {
	var paramTemp = jQuery.extend(true, {}, paramTabPage[tabId]);;
	paramTemp.code = code;
	paramTemp.desc = desc;
	paramTemp.type = type;
	paramTemp.monitorType = type;
	paramTemp.previous=type;
	if(type == "depGroup"){
		paramTemp.title = "科室组指标";
		paramTemp.depGroupCode = code;
		paramTemp.depGroupName = desc;
	}else if(type == "dep"){
		paramTemp.title = "科室指标";
		paramTemp.depCode = code;
		paramTemp.depName = desc;
	}else if(type == "ward"){
		paramTemp.title = "病区指标";
		paramTemp.wardCode = code;
		paramTemp.wardName = desc;
	}else if(type == "clinic"){
		paramTemp.title = "主诊医师指标";
		paramTemp.groupName = code;
	}else if(type == "protomedicus"){
		paramTemp.title = "主任医师指标";
		paramTemp.protomedicus_desc = desc;
		paramTemp.protomedicus = code;
	}else if(type == "physician"){
		paramTemp.title = "主治医师指标";
		paramTemp.physician = code;
		paramTemp.physician_desc = desc;
	}else if(type == "resident"){
		paramTemp.title = "住院医师指标";
		paramTemp.resident = code;
		paramTemp.resident_desc = desc;
	}
	openTab('/pages/yibao/bingzhong/ybbDepLineDrg.jsp', desc + "|" + 'DRGs', type + 'DRGs'+ code, type + 'DRGs' + code, paramTemp);
}

function loadUpperStore(monitorType) {
	var code = paramTabPage[tabId].code;
	var desc = paramTabPage[tabId].desc;
	var type = paramTabPage[tabId].type;
	if(monitorType == "drgs"){
		openTab('/pages/yibao/bingzhong/ybbDepLineAdrg.jsp',desc+"|"+"ADRG",type+'ADRG'+code,type+'ADRG'+code,paramTabPage[tabId]);
	}else if(monitorType == "adrg"){
		openTab('/pages/yibao/bingzhong/ybbDepLineMdc.jsp',desc+"|"+"MDC",type+'MDC'+code,type+'MDC'+code,paramTabPage[tabId]);
	}
	else if(monitorType == "dep"){
		openTab('/pages/yizheng/ywcDisLineDepGroup.jsp',code+"|"+"科室组",type+'depGroupYwcBack'+code,type+'depGroupYwcBack'+code,paramTabPage[tabId]);
	}
}
function loadYibaoDoctorDiv(totalQuota,divId,commonul)
{
	var doctorul = '';
	var doctorStr = '';
	if (doctorSetConfig.length > 0) {
		if(doctorSetConfig[0]==1)
		{
			var data = yibaoDoctorDiv(totalQuota,'主任医师', 'protomedicus');
			var str = data[0];
			var ul = data[1];
			doctorul += '<li role="presentation">';
			doctorul += '	<a href="#protomedicus_' + tabId + '" role="tab" data-toggle="tab" class="top-tab">主任医师</a>';
			doctorul += '</li>';
			doctorStr += '<div role="tabpanel" class="tab-pane" id="protomedicus_' + tabId + '">';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<ul class="nav nav-tabs tabconulcq" role="tablist">'+ul+'</ul>';
			doctorStr += '	<div class="clearfix"></div>';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<div id="quotasId_protomedicus" class="tab-content">'+str+'</div>';
			doctorStr += '</div>';
		}
		if(doctorSetConfig[1]==1)
		{
			var data = yibaoDoctorDiv(totalQuota,'主诊医师' , 'clinic');
			var str = data[0];
			var ul = data[1];
			doctorul += '<li role="presentation">';
			doctorul += '	<a href="#clinic_' + tabId + '" role="tab" data-toggle="tab" class="top-tab">主诊医师</a>';
			doctorul += '</li>';
			doctorStr += '<div role="tabpanel" class="tab-pane" id="clinic_' + tabId + '">';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<ul class="nav nav-tabs tabconulcq" role="tablist">'+ul+'</ul>';
			doctorStr += '	<div class="clearfix"></div>';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<div id="quotasId_clinic" class="tab-content">'+str+'</div>';
			doctorStr += '</div>';
		}
		if(doctorSetConfig[2]==1)
		{
			var data = yibaoDoctorDiv(totalQuota, '主治医师', 'physician');
			var str = data[0];
			var ul = data[1];
			doctorul += '<li role="presentation">';
			doctorul += '	<a href="#physician_' + tabId + '" role="tab" data-toggle="tab" class="top-tab">主治医师</a>';
			doctorul += '</li>';
			doctorStr += '<div role="tabpanel" class="tab-pane" id="physician_' + tabId + '">';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<ul class="nav nav-tabs tabconulcq" role="tablist">'+ul+'</ul>';
			doctorStr += '	<div class="clearfix"></div>';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<div id="quotasId_physician" class="tab-content">'+str+'</div>';
			doctorStr += '</div>';
		}
		if(doctorSetConfig[3]==1)
		{
			var data = yibaoDoctorDiv(totalQuota, '住院医师', 'resident');
			var str = data[0];
			var ul = data[1];
			doctorul += '<li role="presentation">';
			doctorul += '	<a href="#resident_' + tabId + '" role="tab" data-toggle="tab" class="top-tab">住院医师</a>';
			doctorul += '</li>';
			doctorStr += '<div role="tabpanel" class="tab-pane" id="resident_' + tabId + '">';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<ul class="nav nav-tabs tabconulcq" role="tablist">'+ul+'</ul>';
			doctorStr += '	<div class="clearfix"></div>';
			doctorStr += '	<div class="paddingd10"></div>';
			doctorStr += '	<div id="quotasId_resident" class="tab-content">'+str+'</div>';
			doctorStr += '</div>';
		}
		$('#' + tabId + ' #'+commonul).html(doctorul);
		$('#' + tabId + ' #'+divId).html(doctorStr);
		
		$('#' + tabId + ' #'+commonul+' li:eq(0)').addClass("active");
		$('#' + tabId + ' #'+divId+'>.tab-pane:eq(0)').addClass("active");
		
		//给 相关指标 添加单击事件
		$("#"+tabId+" .releated").click(function(){
			//获取要查询的关联指标的指标代码
			var quota_rel = $(this).parents("ul").attr("quota_code");
			var quotaName = $(this).parents(".tab-pane").attr("quotaName");
			var flagCode = $(this).attr("code");
			var monitorName = $('#' + tabId + ' #'+commonul+' li.active a').html();
			var monitorType = $('#' + tabId + ' #'+commonul+' li.active a').attr("href").substr(1).split("_")[0];
			//请求当前指标的关联指标
			$.ajax({
			    url: contextPath+"/DrgsIndexCal/releateQuotas.dhc?quotaCode="+quota_rel+"_RELEATE",
			    type: "POST",
			    dataType: 'JSON',
			    async: false,
			    success: function(result){
			    	var relQuota = result.data;
			    	loadDRGsQuotaRelData(quota_rel,quotaName,monitorName,monitorType,relQuota,flagCode)
			    },
			    error: function(result){}
			});
		});	
		
	}
}

function yibaoDoctorDiv(totalQuota,monitorName,monitorType){
	if(!monitorName) monitorName = ""
	if(paramTabPage[tabId].compareType=="year"){
		compareName = "同期";
	}else if(paramTabPage[tabId].compareType=="month"){
		compareName = "上期";
	}else if(paramTabPage[tabId].compareType=="manage"){
		compareName = "绩效";
	}else if(paramTabPage[tabId].compareType=="std"){
		compareName = "标杆";
	}
	var str = '';
	var ul='';			
	for(var o in totalQuota){
		var QuotaCode = totalQuota[o].children;
		var flagCode = totalQuota[o].code;
		//拼接ul
		if(totalQuota.length>0){
			if(o == 0){
				ul+='<li role="presentation" class="active">';
			}else{
				ul+='<li role="presentation">';
			}
			ul+='<a class="top-tab" href="#'+totalQuota[o].code+'QuaId'+tabId+monitorType+'" role="tab" data-toggle="tab">'+totalQuota[o].name+'</a>';
			ul+='</li>';
		}
		//开始拼接div
		if(o == 0){
			str+='<div role="tabpanel" class="tab-pane active" id="'+totalQuota[o].code+'QuaId'+tabId+monitorType+'">';
		}else{
			str+='<div role="tabpanel" class="tab-pane" id="'+totalQuota[o].code+'QuaId'+tabId+monitorType+'">';
		}
		
		for(var o in QuotaCode){
			var quotas = QuotaCode[o];
			str+=' <div class="paddingd10"> ';
			str += '   <div class="tabconti';
			if(quotas.name==='产能'){
				str += ' blue-bg"><i class="fa fa-users fa-lg"></i>';
			} else if(quotas.name==='效率'){
				str += ' green-bg"><i class="fa fa-stethoscope fa-lg"></i>';
			} else if(quotas.name==='安全'){
				str += ' red-bg"><i class="fa fa-heartbeat fa-lg"></i>';
			} else {
				str += '">';
			}
			str += quotas.name + '</div> ';
			str+='   <ul class="nav nav-tabs tabconulcq" role="tablist"> ';
			for(var o1 in quotas.children){
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				if(o1 == 0){
					str+='       <li role="presentation" class="active"> ';
				}else{
					str+='       <li role="presentation"> ';
				}
				str+='           <a href="#'+quotaCode+'-tc'+tabId+monitorType+'" role="tab" data-toggle="tab">'+quotaName+'</a> ';
				str+='       </li> ';
			}
			str+='   </ul> ';
			str+='   <div class="clearfix"></div> ';
			str+='   <div class="tab-content"> ';
			for(var o1 in quotas.children){
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var releate = quota.releate;
				if(o1 == 0){
					str+='       <div role="tabpanel" class="tab-pane active" compareName="'+compareName+'" monitorName="'+monitorName+'" quotaName="'+quotaName+'" quotaCode="'+quotaCode+'" id="'+quotaCode+'-tc'+tabId+monitorType+'"> ';
				}else{
					str+='       <div role="tabpanel" class="tab-pane" compareName="'+compareName+'" monitorName="'+monitorName+'" quotaName="'+quotaName+'" quotaCode="'+quotaCode+'" id="'+quotaCode+'-tc'+tabId+monitorType+'"> ';
				}
				str+='           <div class="row padding100"> ';
				str+='               <div class="col-xs-5"> ';
				str+=' 					<ul class="nav nav-tabs tabconulcq" role="tablist" quota_code="'+quotaCode+'">  ';
				str+=' 						<li role="presentation" class="active">  ';
				str+=' 						<a href="#'+quotaCode+'bar-tc'+tabId+monitorType+'" role="tab" data-toggle="tab">柱状图</a>  ';
				str+=' 						</li>  ';
				str+=' 						<li role="presentation">  ';
				str+=' 						<a href="#'+quotaCode+'line-tc'+tabId+monitorType+'" role="tab" data-toggle="tab">趋势图</a>  ';
				str+=' 						</li>  ';
				if(quota.releate)
				{
					str+='       <li role="presentation" code = "'+flagCode+'" class = "pull-right releated"> <i class="icon-magnet" title = "关联指标"></i>';
					str+='       </li> ';
				}
				str+='					</ul>'
				str+=' 			<div class="tab-content"> ';
				str+=' 				<div role="tabpanel" class="tab-pane active" id="'+quotaCode+'bar-tc'+tabId+monitorType+'"> ';
				str+=' 					<div class="echartscq" style="width:475px;"><img src="images/pageloading.gif" /></div> ';
				str+=' 				</div> ';
				str+=' 				<div role="tabpanel" class="tab-pane" id="'+quotaCode+'line-tc'+tabId+monitorType+'"> ';
				str+=' 					<div class="echartscq" style="width:475px;"></div> ';
				str+=' 				</div> ';
				str+=' 			</div> ';
				str+='               </div> ';
				str+='               <div class="col-xs-7 dataChangeSel"> ';
				str+='                   <table id="'+quotaCode+'-table'+tabId+monitorType+'" class="table table-striped" cellspacing="0" width="100%" role="grid" aria-describedby="example_info"> ';
				str+='                       <caption class="contaotalsccq">'+monitorName+quotas.name+'('+quotaName+')</caption> ';
				str+='                       <thead> ';
				str+='                           <tr role="row"> ';
				if(releate){
					str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1"></th> ';
				}
				str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending">'+monitorName+'</th> ';
				str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">本期值</th> ';
				str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">'+compareName+'值</th> ';
				str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">增长率</th> ';
				str+='                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">操作</th> ';
				str+='                           </tr> ';
				str+='                       </thead> ';
				str+='                       <tbody></tbody> ';
				str+='                   </table> ';
				str+='               </div> ';
				str+='           </div> ';
				str+='       </div> ';
			}
			str+='   </div> ';
			str+=' </div> ';
		}
		str+='</div>';
	}
	var data = [];
	data.push(str);
	data.push(ul);
	return data;
}

function loadYibaoDoctorLayerData(totalQuota,across) {
	var monitorType = "";
	if (doctorSetConfig.length > 0) {
		if(doctorSetConfig[0]==1)
		{//主任医师
			monitorType = 'protomedicus';
			loadYibaoDoctorData(totalQuota, monitorType, across);
		}
		if(doctorSetConfig[1]==1)
		{//主诊医师
			monitorType = 'clinic';
			loadYibaoDoctorData(totalQuota, monitorType, across);
		}
		if(doctorSetConfig[2]==1)
		{//主治医师
			monitorType = 'physician';
			loadYibaoDoctorData(totalQuota, monitorType, across);
		}
		if(doctorSetConfig[3]==1)
		{//住院医师
			monitorType = 'resident';
			loadYibaoDoctorData(totalQuota, monitorType, across);
		}
	}
}

function loadYibaoDoctorData(totalQuota,monitorType,across){
	for(var o in totalQuota){
		var quotaTypes = totalQuota[o].children;
		for(var o in quotaTypes){
			var quotas = quotaTypes[o];
			for(var o1 in quotas.children){
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var quotaType = quota.type;
				var releate = quota.releate;
				var isLink = quota.islink;
				loadYibaoDoctorDatasub(quotaCode, quotaType, releate, quotaName,monitorType,across,isLink);
			}
		}
	}
}

function loadYibaoDoctorDatasub(quotaCode, quotaType, releate, quotaName,monitorType,across,isLink){
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc='1';//是否获取比较值
	param.monitorType=monitorType;//比较对象： Hosp dep depGroup  mdc adrg drgs ward（病区） resident（住院医师） protomedicus（主任医师）physician（主治医师）
	param.quotaCode=quotaCode;//指标代码
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(data){
		data = data.data;
		var hasCaseDtl = isLink==1?true:false;
		var columns = [	
		               	{ "data": "ccode",
		               	  "createdCell": function (nTd, sData, oData, iRow, iCol) {
							  $(nTd).attr('limit', 30);
							  $(nTd).limit();
						   },
		               		"render":function(obj, type, full){
		               			if(full.ccode==null||full.ccode=="null"){
		               				return "未入组";
	               				}
		               			else if(monitorType=="mdc"||monitorType=="adrg"){//病组线   mdc或adrg
		               				if(full.ccode=="notcode"){
		               					return "未入组";
		               				}
		               				return "<a title ='' href=\"javascript:toNextLayerYiBao("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" + "("+full.ccode+")"+full.ddesc + "</a>";
	               				}
		               			else if(monitorType=="drgs"){
		               				if(full.ccode=="notcode"){
		               					return "未入组";
		               				}
		               				return "("+full.ccode+")"+full.ddesc;
	               				}
		               			else{
		               				if (toNextLayerBool(monitorType)) {
		               					return "<a title ='' href=\"javascript:toNextLayerYiBao("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" + full.ddesc + "</a>";
		               				} 
		               				else {
		               					return full.ddesc;
	               					}
	               				}
		               			
		               		}
		               	},
		               	{ "data": "QuotaValue_1", "type": "numeric-comma",
		               		"render":function(obj, type, full){
		               			full.QuotaValue=full.QuotaValue!=null?full.QuotaValue:'';//强制转换
		               			full.QuotaValuecc=full.QuotaValuecc!=null?full.QuotaValuecc:'';
	               				if(hasCaseDtl && full.QuotaValue!=0){
	               					return "<a href=\"javascript:loadCaseDtl('"+full.ddesc+"|"+quotaName+"','"+full.ccode+"','"+monitorType+"', '"+quotaCode+"')\">"+formatNumber(full.QuotaValue)+"</a>"
	               				}
	               				return "<span>"+formatNumber(full.QuotaValue)+"</span>";
		               		}
		               	},
		               	{ "data": "QuotaValuecc_1", "type": "numeric-comma",
			            	   "render":function(obj, type, full){
			            			   return formatNumber(full.QuotaValuecc);   
			            	   }
		               	},
		               	{ "data": "increasing","type": "number-fate",
		               		"render":function(obj, type, full){
		               			if("ratio"==quotaType){
		               				return gridcompareValuePercent(full.QuotaValue, full.QuotaValuecc);
		               			}
		               			return gridcompareValue(full.QuotaValue, full.QuotaValuecc);
		               		}
		               	},
		               	{ "data": "OPERATION",
		               		"render":function(obj, type, full){
		               			if(across)
	               				{//交叉的情况	科室线下各病种层次	病区线下各科室层次
	               					//去掉病例钻取界面 BY RUANSHULI AT 2017年3月3日15:40:47
		               				return  "<a title='趋势' class='trend-link trendNotSel'><i class='fa fa-line-chart'></i></a>";
		               				"<a title='病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"								
	               					/*+ "<a title='趋势' class='trend-link'><i class='fa fa-line-chart'></i></a>";*/
	               				}
		               			else
	               				{
		               				var operation = "";
		               				if (typeof (param.disBack) == "undefined") {
		               					operation = "<a title='病组' class='jumplink' href=\"javascript:loadDRGs('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-list-alt'></i></a>&nbsp;&nbsp;";
		               				}
	               					return operation
	               					+"<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"								
			            			+ "<a title='趋势' class='trend-link trendNotSel'><i class='fa fa-line-chart'></i></a>" ;
	               				}
	               			}
		               	}];
		var unSortColumnI = 4;
		if(releate){
			columns.splice(0, 0, {
				"data":null,"defaultContent": "","width":"25","className": 'details-control'
			});
			unSortColumnI = 5;
		}
		//调用datatableyb画右侧表格
		var paramsDataTables={order:[],columnDefs:[{"orderable": false,"targets":[unSortColumnI] }],monitorType:monitorType};
		$("#"+quotaCode+"-table"+tabId+monitorType).drgsDataTableyb(columns, data, paramsDataTables);
	});
}
